﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.CompilerServices;


using ConstructionBidOnline.DAL;
using ConstructionBidOnline.DAL.dsMembershipSettingsTableAdapters;
using ConstructionBidOnline.Common;

namespace ConstructionBidOnline.Biz
{
   public class FeaturedFeesSettings:BOBase
    {
       #region Construction / Disposal

        /// <summary>
        /// Default constructor.
        /// </summary>
       protected FeaturedFeesSettings() { }

        #endregion

       #region Public Properties

       #region Instance Properties

       /// <summary>
       /// PKID of the FeaturedFeesSettings.
       /// </summary>
       public int FeaturedFeesID
       {
           get { return _featuredfeesID; }
           set
           {
               if (_featuredfeesID != value)
               {
                   if (OnPropertyChanging("FeaturedFeesID", _featuredfeesID, value))
                   {
                       int oldValue = _featuredfeesID;
                       _featuredfeesID = value;

                       OnPropertyChanged("FeaturedFeesID", oldValue, value);
                   }
               }
           }
       }  private int _featuredfeesID = -1;

       


       


       /// <summary>
       /// Featured Job Fees Value.
       /// </summary>
       /// 

       public decimal FeaturedJobFees	
       {
           get { return _featuredjobfees; }
           set
           {
               if (_featuredjobfees != value)
               {
                   if (OnPropertyChanging("FeaturedJobFees", _featuredjobfees, value))
                   {
                       decimal oldValue = _featuredjobfees;
                       _featuredjobfees = value;
                       OnPropertyChanged("FeaturedJobFees", oldValue, value);
                   }
               }
           }
       }  private decimal _featuredjobfees = 0;


       /// <summary>
       /// Featured Directory Fees Value.
       /// </summary>
       /// 

       public decimal FeaturedDirectoryFees
       {
           get { return _featuredDirectoryFees; }
           set
           {
               if (_featuredDirectoryFees != value)
               {
                   if (OnPropertyChanging("FeaturedDirectoryFees", _featuredDirectoryFees, value))
                   {
                       decimal oldValue = _featuredDirectoryFees;
                       _featuredDirectoryFees = value;
                       OnPropertyChanged("FeaturedDirectoryFees", oldValue, value);
                   }
               }
           }
       }  private decimal _featuredDirectoryFees = 0;


       #endregion

       #endregion

       #region Public Methods

       #region CreateNew

       /// <summary>
       /// Creates a new, empty ConsultantSettings object.
       /// </summary>
       public static FeaturedFeesSettings CreateNew()
       {
           FeaturedFeesSettings obj = new FeaturedFeesSettings();

           // Switch state to Added prior to initializing property values.
           obj.ObjState = ObjectState.Added;

           //obj.ValidUpTo = DateTime.Now;

           return (obj);
       }


       [MethodImpl(MethodImplOptions.Synchronized)]
       public static FeaturedFeesSettings CreateNew(FeaturedFeesSettingsCollection collection)
       {
           FeaturedFeesSettings obj = CreateNew();

           // Get next/unique ID for the new object.
           int minVal = 0;
           foreach (FeaturedFeesSettings FeaturedFeesSettings in collection)
           {
               if (FeaturedFeesSettings.FeaturedFeesID < minVal)
                   minVal = FeaturedFeesSettings.FeaturedFeesID;
           }
           obj.FeaturedFeesID = --minVal;
           collection.Add(obj);

           return (obj);
       }

       #endregion

       #region GetAllFeaturedFeesSettings

       /// <summary>
       /// Returns a collection of all FeaturedFeesSettings.
       /// </summary>
       public static FeaturedFeesSettingsCollection GetAllFeaturedFeesSettings()
       {
          FeaturedFees_SettingsTableAdapter adapter = new FeaturedFees_SettingsTableAdapter();
           adapter.Connection = AppSettings.GetDbConn();

           dsMembershipSettings.FeaturedFees_SettingsDataTable tbl = adapter.GetData(null);

           FeaturedFeesSettingsCollection list = new FeaturedFeesSettingsCollection();

           if (tbl.Rows.Count > 0)
           {
               foreach (dsMembershipSettings.FeaturedFees_SettingsRow row in tbl.Rows)
               {
                   FeaturedFeesSettings FeaturedFeesSettings = new FeaturedFeesSettings();
                   RelationalToObject(FeaturedFeesSettings, row);
                   list.Add(FeaturedFeesSettings);
               }
           }

           return (list);
       }

       #endregion

       #region GetFeaturedFeesSettingsByID

       /// <summary>
       /// Returns an FeaturedFeesSettings object for the specified 'featuredfeesID' or null if no FeaturedFeesSettings with the specified parameter(s) exists.
       /// </summary>
       public static FeaturedFeesSettings GetFeaturedFeesSettingsByID(int featuredfeesID)
       {
           FeaturedFees_SettingsTableAdapter adapter = new FeaturedFees_SettingsTableAdapter();
           adapter.Connection = AppSettings.GetDbConn();
           dsMembershipSettings.FeaturedFees_SettingsDataTable tbl = adapter.GetData(featuredfeesID);

           if (tbl.Rows.Count == 1)
           {
               FeaturedFeesSettings ffs = new FeaturedFeesSettings();
               RelationalToObject(ffs, tbl.Rows[0]);
               return (ffs);
           }
           else if (tbl.Rows.Count > 1)
               throw new ApplicationException("Database integrity error: Specified 'featuredfeesID' returned more than one User record.");

           return (null);
       }

       #endregion

       #region Update

       /// <summary>
       /// Updates the specified FeaturedFeesSettings.
       /// </summary>
       public static void Update(FeaturedFeesSettings obj)
       {
           bool updateFeaturedFeesSettings = false;

           // Do not update invalid objects.
           if (!obj.Validate())
           {
               StringBuilder sb = new StringBuilder(2048);
               sb.Append("The object being updated has one or more invalid properties; the Update() operation for this object has been cancelled.\nError(s):");
               foreach (ValidationError err in obj.Errors)
                   sb.Append("\n* " + err.Element + ": " + err.Message);

               throw new InvalidObjectException(sb.ToString());
           }
           else
           {
               updateFeaturedFeesSettings = (obj.ObjState != ObjectState.Unchanged);

               if (!updateFeaturedFeesSettings)
                   return;
           }

           ObjectState originalObjectState = obj.ObjState;

           dsMembershipSettings.FeaturedFees_SettingsDataTable tbl = null;
           if (updateFeaturedFeesSettings)
           {

               FeaturedFees_SettingsTableAdapter adapter = new FeaturedFees_SettingsTableAdapter();
               adapter.Connection = AppSettings.GetDbConn();


               tbl = new dsMembershipSettings.FeaturedFees_SettingsDataTable();
               dsMembershipSettings.FeaturedFees_SettingsRow row = tbl.NewFeaturedFees_SettingsRow();
               ObjectToRelational(obj, tbl, row);

               adapter.Update(tbl);

               if (originalObjectState == ObjectState.Deleted)
                   obj = null;
               else RelationalToObject(obj, tbl.Rows[0]);
           }
       }

       #endregion

       #region Validate

       /// <summary>
       /// Validates the object based on its properties at the time of the call; updates the Errors property.
       /// </summary>
       public override bool Validate()
       {
           Errors.Clear();

           if (ObjState == ObjectState.Unchanged)
           {
               // By definition, unchanged objects are valid.
               return (true);
           }
           else if (ObjState == ObjectState.Uninitialized)
           {
               Errors.Add(new ValidationError("object", "Object is uninitialized.", ValidationError.Severity.Error));

               // No need to proceed past this error.
               return (false);
           }
           else if ((ObjState == ObjectState.Deleted) && (FeaturedFeesID <= 0))
           {
               // Deleted items must have 'real' (i.e. non-negative, non-zero) key(s) to be valid.
               Errors.Add(new ValidationError("FeaturedFeesID", "Deleted object has an invalid PKID.", ValidationError.Severity.Error));

               // No need to proceed past this error.
               return (false);
           }
           else  // ObjState == Added | Modified
           {

               // MembershipFees is required.
               if ((FeaturedJobFees < 0) )
               {
                   Errors.Add(new ValidationError("FeaturedJobFees", "FeaturedJobFees is required.", ValidationError.Severity.Error));
               }
               else if (ObjState == ObjectState.Added)
               {

               }

           }

           return (Errors.Count == 0);
       }

       #endregion

       #region ToString

       /// <summary>
       /// User-friendly string represetation of this object.
       /// </summary>
       public override string ToString()
       {
           return (String.Format("FeaturedFeesSettings: FFID={0}, FeaturedJobFees={1}, {2}", FeaturedFeesID, FeaturedJobFees));
       }

       #endregion


       #endregion
    }





   /// <summary>
   /// Collection of 0 or more SubAdmin objects.
   /// </summary>

   public class FeaturedFeesSettingsCollection : List<FeaturedFeesSettings>
   {

       #region Types

       public class UserComparer : IComparer<FeaturedFeesSettings>
       {
           public int Compare(FeaturedFeesSettings user1, FeaturedFeesSettings user2)
           {
               return (String.Compare(user1.FeaturedJobFees.ToString(), user2.FeaturedJobFees.ToString()));
           }
       }

       #endregion

       #region Public Methods

       #region FindByFeaturedFeesSettingsID

       public FeaturedFeesSettings FindByFeaturedFeesSettingsID(int FeaturedFeesSettingsID)
       {
           for (int ndx = 0; ndx < this.Count; ndx++)
               if (this[ndx].FeaturedFeesID == FeaturedFeesSettingsID)
                   return (this[ndx]);

           return (null);
       }

       #endregion

       

       #endregion

   }

}
